<template>
  <div class="play_panel">
    <div class="list">
      <div class="list_title">
        <span>播放列表：共 {{ getMusicList.length }} 首</span>
        <!-- <span>播放列表：共 10 首</span> -->
        <span class="el-icon-delete delete" @click="delall"></span>
      </div>
      <div class="list_box">
        <my-scroll :opacity="0.5">
          <div v-for="(item, index) in getMusicList" :key="index" class="item">
            <span class="gif" v-if="getIndex == index">
              <img src="/images/dh.gif" alt="" />
            </span>
            <span
              class="name"
              :class="getIndex == index ? 'active_color' : ''"
              @click="playSong(index)"
              >{{ item.name }}</span
            >
            <span
              class="el-icon-delete delete"
              @click="deleteSong(index)"
            ></span>
          </div>
        </my-scroll>
      </div>
    </div>
    <div class="info">
      <div class="imgbox">
        <img :src="getImgUrl" alt="" />
      </div>
      <div class="info_box">
        <div class="name">{{ getName }} -- {{ getAuthor }}</div>
        <div class="lyrics">
          <my-scroll ref="mini_scroll" :opacity="0">
            <ul>
              <li v-for="(item, index) in getLyrics" :key="index">
                {{ item[1] }}
              </li>
            </ul>
          </my-scroll>
        </div>
      </div>
    </div>
    <div class="control">
      <div class="model" @click="changeModel">
        <i v-if="getModel == 0" class="iconfont icon-xunhuan"></i>
        <i v-else-if="getModel == 1" class="iconfont icon-xunhuan1"></i>
        <i v-else-if="getModel == 2" class="iconfont icon-suiji"></i>
      </div>
      <div>
        <i @click="prevSong" class="iconfont icon-shangyishou"></i>
      </div>
      <div class="play_pause" @click="play_pause">
        <i v-if="!getState" class="iconfont icon-bofang"></i>
        <i v-else class="iconfont icon-tingzhi"></i>
      </div>
      <div>
        <i @click="nextSong" class="iconfont icon-xiayishou"></i>
      </div>

      <div class="close">
        <i class="iconfont icon-close" @click="close"></i>
      </div>
    </div>
  </div>
</template>
<script>
import { mapGetters } from "vuex"
export default {
  data() {
    return {}
  },
  computed: {
    // vue辅助函数
    ...mapGetters([
      "getName",
      "getAuthor",
      "getMusicUrl",
      "getImgUrl",
      "getIndex",
      "getModel",
      "getMusicList",
      "getState",
      "getLyrics",
      "getCurrentTime",
      "getLyricsIndex",
      "getCanPlay",
    ]),
  },
  watch: {
    getLyricsIndex: function(newValue, oldValue) {
      if (newValue == 0) {
        this.scrolltop = 0
      }
      if (newValue >= 1) {
        this.scrolltop = newValue * 25
      }
      this.$refs.mini_scroll.$refs.vs.scrollTo({
        y: this.scrolltop,
      })
    },
  },
  methods: {
    // 点击播放列表
    playSong(index) {
      this.$store.commit("upDateIndex", index)
    },
    // 上一首
    prevSong() {
      this.$store.commit("prev")
    },

    // 下一首
    nextSong() {
      this.$store.commit("next")
    },

    // 播放__暂停
    play_pause() {
      this.$store.commit("play_pause")
    },

    //删除播放列表里的歌曲
    deleteSong(index) {
      this.$store.commit("delete", index)
    },

    // 清空歌曲列表
    delall() {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$store.commit("deleteAll")
          this.$message({
            type: "success",
            message: "删除成功!",
          })
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          })
        })
    },
    // 点击更换播放模式
    changeModel() {
      let model = this.getModel + 1
      if (model > 2) {
        model = 0
      }
      this.$store.commit("changeModel", model)
    },
    close() {
      this.$EventBus.$emit("showPanel")
    },
  },
}
</script>
<style lang="scss" scoped>
@import "../../scss/common.scss";
.play_panel {
  position: fixed;
  right: 0;
  top: 0;
  height: 100vh;
  width: 21%;
  min-width: 300px;
  max-width: 380px;
  background: white;
  z-index: 100;
  box-shadow: 0px 0px 20px 2px rgba(0, 0, 0, 0.2);
  .list {
    height: calc(100vh - 120px);
    .list_title {
      height: 40px;
      font-size: 17px;
      display: flex;
      justify-content: space-between;
      border-bottom: 1px solid rgb(199, 197, 197);
      position: relative;
      z-index: 5;
      span {
        z-index: 1;
        color: rgb(143, 141, 141);
        display: inline-block;
        height: 40px;
        line-height: 40px;
        padding: 0px 10px;
      }
      .delete:hover {
        color: #ad0a49;
      }
    }
    .list_box {
      height: calc(100% - 40px);
      .item {
        z-index: 1;
        line-height: 30px;
        height: 30px;
        color: rgb(143, 141, 141);
        font-size: 14px;
        width: 100%;
        vertical-align: middle;
        display: flex;
        .gif {
          padding-left: 10px;
        }
        .name {
          vertical-align: middle;
          padding: 0px 10px;
          display: inline-block;
          flex: auto;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .active_color {
          color: $active;
        }
        .delete {
          vertical-align: middle;
          width: 30px;
          display: inline-block;
          height: 30px;
          line-height: 30px;
          text-align: center;
          padding-right: 10px;
        }
        .delete:hover {
          color: crimson;
        }
      }
      .item:hover {
        cursor: pointer;
        background: $active;
        color: white;
      }
      .item:hover .name {
        color: white !important;
      }
    }
  }
  .info {
    width: 100%;
    height: 60px;
    display: flex;
    box-shadow: 0px 0px 10px 2px rgba(0, 0, 0, 0.2);
    .imgbox {
      height: 60px;
      width: 60px;
      overflow: hidden;
      position: relative;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .info_box {
      width: calc(100% - 60px);
      height: 60px;
      div {
        box-sizing: border-box;
        width: 100%;
        height: 30px;
        line-height: 30px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .name {
        padding: 0px 10px;
        font-size: 14px;
      }
      .lyrics {
        padding: 0px 10px;
        font-size: 12px;
        color: $primary;
        ul {
          width: 100%;
          li {
            height: 25px;
            line-height: 25px;
            width: 100%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
    }
  }
  .control {
    width: 100%;
    height: 60px;
    display: flex;
    padding: 0px 10px;
    box-sizing: border-box;
    background: $primary;
    transition: 0.5s;
    div {
      width: 20%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      i {
        font-size: 45px;
        color: white;
      }
      i:hover {
        cursor: pointer;
      }
    }
    .model {
      i {
        font-size: 34px;
      }
    }
    .close {
      i {
        font-size: 21px;
      }
    }
    .play_pause {
      i {
        font-size: 55px;
      }
    }
  }
}
</style>
